﻿<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/C#" runat="server">
        private void RegUser(object sender, EventArgs e)
        {
            if (!RegValidateValues())
            {
                return;
            }
            if (Request["wid"] == null || Request["scid"] == null)
            {
                litinfo.Text = "参数错误";
                return;
            }
            int intWID = Convert.ToInt32(Request["wid"].ToString());
            using (DataAccess.DBManager objDBManager = new DataAccess.DBManager())
            {
                objDBManager.BeginTransaction();
                try
                {
                    using (BusinessLogic.ClassFactory.ClientsFactory objClientsFactory = new BusinessLogic.ClassFactory.ClientsFactory())
                    {
                        BusinessLogic.BusinessRules.Clients objClients = objClientsFactory.NewInstance();
                        objClients.DataItem.chvClientsAddress = "";
                        objClients.DataItem.chvClientsEmail = "";
                        objClients.DataItem.chvClientsLoginID = this.RegName.Value;
                        objClients.DataItem.chvClientsLoginPSD = EncryptUtily.EncryptUtily.LoginEncrypt(this.RegPassword.Value);
                        objClients.DataItem.chvClientsName = "";
                        objClients.DataItem.chvClientsPhone = "";
                        objClients.DataItem.chvClientsTel = "";
                        objClients.DataItem.intWSID = intWID;
                        objClients.DataItem.intClientsSex = (int)Common.Utility.ClientsSex.Secret;
                        objClients.DataItem.intClientsState = (int)Common.Utility.ClientsState.Enabled;
                        objClients.DataItem.intClientsType = (int)Common.Utility.ClientsType.Normal;
                        objClients.Insert();
                        //提交
                        objDBManager.Commit();
                        int intSCID = Convert.ToInt32(Request["scid"].ToString());
                        ShowDownlist(intSCID, intWID);
                    }
                }
                catch (Exception ex)
                {
                    litinfo.Text = "出错啦 请联系网站管理员";
                    objDBManager.Rollback();
                    return;
                }
            }
        }

        /// <summary>
        /// 验证输入注册
        /// </summary>
        private bool RegValidateValues()
        {
            bool bolIsValidate = true;
            if (this.RegName.Value.Trim().Length == 0)
            {
                litinfo.Text = "请填写用户名";
                bolIsValidate = false;
            }
            if (!RegexOnly_Number_Litter(this.RegName.Value))
            {
                litinfo.Text = "用户名请使用数字,字母,下划线组合 ";
                bolIsValidate = false;
            }
            if (this.RegPassword.Value != this.RegConfirm_password.Value)
            {
                litinfo.Text = "两次密码不一致";
                bolIsValidate = false;
                return bolIsValidate;
            }

            BusinessLogic.ClassFactory.ClientsFactory objUserWebRelationFactory = new BusinessLogic.ClassFactory.ClientsFactory();
            BusinessLogic.BusinessRules.Clients objUserWebRelation = objUserWebRelationFactory.CreatorBySql(string.Format(" chvClientsLoginID ='{0}' and intWSID={1} ", this.RegName.Value, RichECMS.State.intWSID));
            if (objUserWebRelation != null)
            {
                litinfo.Text = "该用户名已经被使用,请另选一个用户名";
                bolIsValidate = false;
                return bolIsValidate;
            }
            return bolIsValidate;
        }

        /// <summary>
        /// 验证登录
        /// </summary>
        private bool LoginValidateValues()
        {
            bool bolIsValidate = true;
            if (this.Login_Name.Value.Trim().Length == 0)
            {
                litinfo.Text = "请填写用户名";
                bolIsValidate = false;
            }
            return bolIsValidate;
        }

        private void BtnLogin(object sender, EventArgs e)
        {
            if (!LoginValidateValues())
            {
                return;
            }
            try
            {
                using (BusinessLogic.ClassFactory.ClientsFactory objClientsFactory = new BusinessLogic.ClassFactory.ClientsFactory())
                {
                    BusinessLogic.BusinessRules.Clients objClients = objClientsFactory.CreatorBySql(string.Format("chvClientsLoginID ='{0}' ", this.Login_Name.Value.Replace('\'', '\"')));
                    if (objClients == null)
                    {
                        litinfo.Text = "用户名不存在，请检查";
                        return;
                    }
                    else
                    {
                        string strpsd = EncryptUtily.EncryptUtily.LoginEncrypt(this.Login_password.Value);
                        if (objClients.DataItem.chvClientsLoginPSD != EncryptUtily.EncryptUtily.LoginEncrypt(this.Login_password.Value))
                        {
                            litinfo.Text = "密码错误，请检查";
                            return;
                        }
                        else
                        {
                            if (Request["wid"] == null || Request["scid"] == null)
                            {
                                litinfo.Text = "参数错误";
                                return;
                            }
                            int intWID = Convert.ToInt32(Request["wid"].ToString());
                            int intSCID = Convert.ToInt32(Request["scid"].ToString());
                            ShowDownlist(intSCID, intWID);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                litinfo.Text = "出错啦 请联系网站管理员";
            }
        }

        private void ShowDownlist(int intSCID, int intWID)
        {
            BusinessLogic.ClassFactory.SectionsFactory objSectionsFactory = new BusinessLogic.ClassFactory.SectionsFactory();
            BusinessLogic.BusinessRules.Sections objSections = objSectionsFactory.CreatorBySql(string.Format(" intSectionID={0} and intWSID={1}", intSCID, intWID));
            if (objSections != null)
            {
                litscname.Text = objSections.DataItem.chvSTCName;
            }
            BusinessLogic.ClassFactory.ArtSecRelationFactory objArtSecRelationFactory = new BusinessLogic.ClassFactory.ArtSecRelationFactory();
            BusinessLogic.BusinessRules.ArtSecRelation objArtSecRelation = objArtSecRelationFactory.CreatorBySql(string.Format(" intSectionID={0} and intWSID={1}", intSCID, intWID));
            if (objArtSecRelation != null)
            {
                BusinessLogic.ClassFactory.ArticleFactory objArticleFactory = new BusinessLogic.ClassFactory.ArticleFactory();
                BusinessLogic.BusinessRules.Article objArticle = objArticleFactory.CreatorBySql(string.Format(" intArticleid={0} and intWSID={1}", objArtSecRelation.DataItem.intArticleID, intWID));
                if (objArticle != null)
                {
                    this.DownloadLink.HRef = "../pcfiles/Files/" + objArticle.DataItem.chvFilePath;
                    this.DownloadLink.InnerHtml = objArticle.DataItem.chvTitle;
                }
            }
            this.linkparent.Visible = true;
            this.formwrapper.Visible = false;
            this.infoshow.Visible = false;
        }
        
        /// <summary>
        /// 验证字符串是否只由数字字幕下划线组成 下划线不能开头
        /// </summary>
        /// <param name="strSource"></param>
        /// <returns></returns>
        protected bool RegexOnly_Number_Litter(string strSource)
        {
            Regex re = new Regex(@"^(?!_)(?!.*?_$)[a-zA-Z0-9_\u4e00-\u9fa5]+$", RegexOptions.IgnoreCase);
            if (!re.IsMatch(strSource))
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    </script>
    <style type="text/css">
<!--
body {
font-family: Arial,  Helvetica, sans-serif;
font-size:12px;
color:#666666;
background:#fff;
text-align:center;



}



* {
margin:0;
padding:0;
}



a {
color:#1E7ACE;
text-decoration:none;  
}



a:hover  {
color:#000;
text-decoration:underline;
}
h3 {
font-size:14px;
font-weight:bold;
}



pre,p {
color:#1E7ACE;
margin:4px;
}
input, select,textarea {
padding:1px;
margin:2px;
font-size:11px;
}
.buttom{
padding:1px  10px;
font-size:12px;
border:1px #ccc solid;
background:#D0F0FF;
cursor:pointer;
}
#formwrapper {
width:584px;
margin:15px  auto;
padding:20px;
text-align:left;
border:1px #ccc solid;
height:auto;
overflow:visible;
}

#autodiv {
width:100%;
height:auto;
overflow:visible;
float:left;
}

.fieldsetReg
{width:200px;
 margin-right:20px;
 }

.fieldsetReg label {
width:60px;
}

.fieldsetLogin
{width:320px;}

.fieldsetLogin label {
width:80px;
}

fieldset {
padding:10px;
margin-top:5px;
border:1px solid #ccc;
background:#fff;
float:left;
display:block;
}



fieldset legend  {
color:#1E7ACE;
font-weight:bold;
padding:3px  20px 3px 20px;
border:1px solid #ccc;  
background:#fff;
}



fieldset label {
float:left;
width:120px;
text-align:right;
padding:4px;
margin:1px;
}



fieldset div {
clear:left;
margin-bottom:2px;
}



.enter{  text-align:center;}
.clear {
clear:both;
}



-->
</style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="linkparent" runat="server" visible="false">
        <table width="100%" cellspacing="0" cellpadding="0" border="0">
            <tbody>
                <tr>
                    <td height="24" style="border-bottom: #e1e1e1 1px solid; text-align: left;">
                        <img border="0" align="absmiddle" src="../images/end_i.gif">&nbsp;<a href="#"><strong style="color:#333333"><asp:Literal
                            ID="litscname" runat="server"></asp:Literal></strong></a>
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                </tr>
            </tbody>
        </table>
        <table width="100%" cellspacing="0" cellpadding="0" border="0">
            <tbody>
                <tr align="left">
                    <td height="24">
                        <img border="0" align="absmiddle" src="../images/dian.jpg">&nbsp;<a id="DownloadLink"
                            runat="server" style="font: 12px;color:#000;"></a>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <div id="infoshow" runat="server" visible="true">
        <asp:Literal ID="litinfo" runat="server"></asp:Literal></div>
    <div id="formwrapper" runat="server" visible="true">
        <div id="autodiv">
            <fieldset class="fieldsetReg">
                <legend>用户登录</legend>
                <div style="height: 11px;">
                    &nbsp;</div>
                <div>
                    <label for="Name">
                        用户名</label>
                    <input type="text" name="Name" id="Login_Name" runat="server" size="18" maxlength="30" /><br />
                </div>
                <div style="height: 10px;">
                    &nbsp;</div>
                <div>
                    <label for="password">
                        密码</label>
                    <input type="password" name="password" runat="server" id="Login_password" size="18"
                        maxlength="15" /><br />
                </div>
                <div class="cookiechk">
                    <label>
                        &nbsp;</label>
                    <asp:Button ID="btnLogin" runat="server" CssClass="buttom" Text="登录" OnClick="BtnLogin" />
                </div>
            </fieldset>
            <fieldset class="fieldsetLogin">
                <legend>用户注册</legend>
                <div>
                    <label for="Name">
                        用户名</label>
                    <input type="text" name="Name" id="RegName" runat="server" value="" size="18" maxlength="15" />
                    *(最多30个字符)<br />
                </div>
                <div>
                    <label for="password">
                        密码</label>
                    <input type="password" name="password" runat="server" id="RegPassword" size="18"
                        maxlength="15" />
                    *(最多15个字符)<br />
                </div>
                <div>
                    <label for="confirm_password">
                        重复密码</label>
                    <input type="password" name="confirm_password" runat="server" id="RegConfirm_password"
                        size="18" maxlength="15" />
                    *<br />
                </div>
                <div class="enter">
                    <asp:Button ID="BtnReg" runat="server" CssClass="buttom" Text="注册" OnClick="RegUser" />
                    <input name="Submit" type="reset" class="buttom" value="重置" />
                </div>
            </fieldset>
        </div>
        <div style="font: 0px/0px sans-serif; clear: both; display: block">
        </div>
    </div>
    </form>
</body>
</html>
